<?php

class Metrics_model extends CI_Model {
   function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
	//get counter name
	function get_counter_name($counter_id)
	{
		$query=$this->db->query("select name from perfmon.counters where id=$counter_id");
		return $query->row()->name;
	}
	//get values for one counter of one server
	function get_single_counter($servername,$counter_id)
	{
		//get counter name
		$query=$this->db->query("select name from perfmon.counters where id=$counter_id");
		$counter_name=$query->row()->name;
		$query->free_result();
		//get values associated with counter
		$query=$this->db->query("select counter_name, timestamp,value from perfmon.$servername where counter_id=$counter_id order by timestamp desc");
		$i=0;
			foreach($query->result_array() as $row)
			{
				$reading[$i]=array(($row['timestamp'])*1000, $row['value']);
				$i++;
			}
		$rawdata[$counter_name]=json_encode($reading);
		$query->free_result();
	    return $rawdata;
	}
}	
?>
